﻿using System;
using System.Collections.Generic;
using System.Text;
using Common.Utilities;

namespace Workflows.Components.ETL
{
    /// <summary>
    /// 
    /// </summary>
    public class LongestSubSequenceStringComparer:IFuzzyFieldComparer
    {
        #region IFuzzyFieldComparer Members

        public double CompareSimilarity(string fieldValue1, string fieldValue2)
        {
            if (!string.IsNullOrEmpty(fieldValue1) && !string.IsNullOrEmpty(fieldValue2))
            {
                double commonSeqLen = (double)StringUtil.LongestCommonSubsequence(fieldValue1, fieldValue2);
                return commonSeqLen * 2 / (fieldValue1.Length + fieldValue2.Length);
            }
            else
                return 0.0;
        }

        #endregion
    }
}
